#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //out of time
    int ans1(unsigned int left, unsigned int right){
        unsigned int m = right - left + 1;
        int n;
        if(right != 0){
            n = O2B(right).size();
        }else{
            n = 1;
        }
        vector<int> index(n, 1);
        for(int i = 0; i != m; i++){
            unsigned int temp = left + i;
            for(int j = 0; j != n; j++){
                if(temp % 2 == 1 && index[j] == 1){
                    index[j] = 1;
                }else{
                    index[j] = 0;
                }
                temp = temp / 2;
            }

            if(*max_element(index.begin(), index.end()) == 0){
                break;
            }
        }

        unsigned int ret = 0;
        for(int i = n-1; i >= 0; i--){
            ret = ret * 2 + index[i];
        }

        return ret;
    }

    vector<int> O2B(unsigned int x){
        vector<int> b;
        while(x > 0){
            b.push_back(x % 2);
            x = x / 2;
        }
        return b;
    }

    int ans2(int left, int right){
        int shift = 0;

        while (left < right) {
            left = left >> 1;
            right = right >> 1;
            ++shift;
        }
        return left << shift;
    }
};

void test1(){
    Solution s;
    int left = 5, right = 7;

    int ret = s.ans2(left, right);
    cout << ret << endl;
}

void test2(){
    Solution s;
    int left = 0, right = 0;

    int ret = s.ans2(left, right);
    cout << ret << endl;
}

void test3(){
    Solution s;
    int left = 1, right = 2147483647;

    int ret = s.ans2(left, right);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}